package com.company.behavioral.observer_pattern.subject;

import com.company.behavioral.observer_pattern.observer.Observer;

import java.util.ArrayList;

/**
 * 指挥部
 * @ClassName AllyControlCenter
 * @Author tiezheng.han
 * @Date 2020/9/7 10:23
 **/
public abstract class AllyControlCenter {

    /**
     * 战队名称
     */
    protected String allyName;

    /**
     * 定义一个集合用于战队成员
     */
    protected ArrayList<Observer> players = new ArrayList<>();

    public String getAllyName() {
        return allyName;
    }

    public void setAllyName(String allyName) {
        this.allyName = allyName;
    }

    /**
     * 注册方法
     * @param obs
     */
    public void join(Observer obs){
        System.out.println(obs.getName() + "加入" + this.allyName + "战队");
        players.add(obs);
    }

    /**
     * 注销方法
     */
    public void quit(Observer obs){
        System.out.println(obs.getName() + "退出" + this.allyName + "战队");
        players.remove(obs);
    }

    /**
     * 声明抽象方法
     * @param name
     */
    public abstract void notifyObserver(String name);
}
